/*
 * MainFrame.java
 *
 * Created on April 2, 2008, 10:24 AM
 */
package fatclientnbp;

import Model.Trip;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.util.Observable;
import java.util.Observer;
import java.util.TreeSet;
import javax.swing.JPanel;
import javax.swing.plaf.DimensionUIResource;

/**
 *
 * @author  hajo
 */
public class MainFrame extends javax.swing.JFrame implements Observer {

    private SearchPanel searchPanel;
    private MainController controller;
    private JPanel currentPanel;
    private MainModel model;
    private BookingPanel bookingPanel;
    private ConfirmationPanel confirmationPanel;

    /** Creates new form MainFrame */
    public MainFrame() {
        initComponents();
    }


    private void initComponents() {

        this.model = new MainModel();

        model.addObserver(this);

        controller = new MainController(model);

        searchPanel = new SearchPanel(controller, model);

        this.setLayout(new BorderLayout());

        currentPanel = searchPanel;

        this.add(currentPanel, BorderLayout.CENTER);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("FatClient");

        //this.setResizable(false);

        pack();
    }// </editor-fold>

    public void update(Observable o, Object arg) {
        int state = model.getState();
        if ( state == MainModel.SEARCH_STATE) {
            currentPanel = searchPanel;
            //this.setContentPane(currentPanel);
        }
        else if (state == MainModel.SELECT_STATE) {
            TreeSet<Trip> trips = model.getTrips();
            if (trips != null) {
                currentPanel = new ResultPanel(trips, controller);
                //this.setContentPane(currentPanel);
              
            }else{
                System.out.println("FEL!!!");
            }
        }
        else if (state == MainModel.BOOK_STATE) {
            Trip t=model.getChosenTrip();
            currentPanel=new BookingPanel(t, model.getSearchParameters().getPassangers(), controller);
            //this.setContentPane(bookingPanel);
            //repaint();
            System.out.println("State  : Book");
        }
        else if(state == MainModel.FINISHED_STATE)
        {
           currentPanel = new ConfirmationPanel(model.getBookings(), controller);
           //this.setContentPane(confirmationPanel);
           //repaint();
        }
        //currentPanel.repaint();
        this.setContentPane(currentPanel);
        this.pack();
       
    }    // End of variables declaration
}
